@include "misc.awk"
@include "student.awk"

#unpaired: difference means, vars, even sample sizes
function theSame(a1,a2,_level,  
                 i,n1,n2,sum1,sum2,sq1,sq2) {
    _level = the(_level,95)
    for(i in a1) { n1++; sum1 += a1[i]; sq1 += a1[i]^2 }
    for(i in a2) { n2++; sum2 += a2[i]; sq2 += a2[i]^2 }
    return unpariedT(_level,n1,n2,sum1,sum2,sq1,sq2) 
}
function unpariedT(level,n1,n2,sum1,sum2,sq1,sq2,
                   v1,v2,mu1,mu2,df,t,crit) {
    v1   = (sq1-((sum1*sum1)/n1))/(n1-1) 
    v2   = (sq2-((sum2*sum2)/n2))/(n2-1) 
    mu1  = sum1/n1
    mu2  = sum2/n2
    df   = (v1/n1+v2/n2)^2 / ((v1/n1)^2/(n1-1)+(v2/n2)^2/(n2-1))
    t    = (mu1 - mu2) / sqrt(v1/n1  + v2/n2)
    crit = critical(int(df+0.5), level)
    #print mu1,mu2,df,t,crit
    return (abs(t) < crit) ? 1 : 0 
}
